﻿using System;
using System.IO;

namespace VCommons
{
    public class FileUtil
    {
        public static void WriteFile(string fileContent, string outputFilePath)
        {
            string directoryPath = outputFilePath.Substring(0, outputFilePath.LastIndexOf("\\"));
            if (!Directory.Exists(directoryPath))
                Directory.CreateDirectory(directoryPath);

            StreamWriter sw = null;
            sw = new StreamWriter(outputFilePath, false);
            sw.Write(fileContent);
            sw.Close();
            sw = null;
        }

        public static string ReadFile(string filePath)
        {
            StreamReader sr = null;
            sr = new StreamReader(filePath);
            return sr.ReadToEnd();
        }

        public static string ReadFile(Stream fileStream)
        {
            StreamReader sr = null;
            sr = new StreamReader(fileStream);
            return sr.ReadToEnd();
        }
    }
}
